// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import App from './App';
import router from './router';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import * as Api from '@/api';
import { setStore, getStore, removeStore } from '@/utils/storage';
import '@/assets/fonts/iconfont.css';
import './style/index.scss'; // 公共样式
import util from '@/utils/util';
import authInfo from '@/utils/authInfo';
import Viewer from 'v-viewer';
import 'viewerjs/dist/viewer.css';
import * as echarts from 'echarts';
import filters from '@/utils/filter';
import wsConnection from '@/utils/socket';
import wsConnectionRomote from '@/utils/remoteSocket';
import Vuex from 'vuex';
import store from './store/store';
import Video from 'video.js';
import Global from '@/utils/global';
import Dict from '@/utils/dict';
import * as Validate from '@/utils/validate';

import TheDialog from '@/components/the-dialog';
import ThePager from './components/the-pager';
import TheImageViewer from './components/the-image-viewer';

import VDistpicker from 'v-distpicker';

Vue.component('the-dialog', TheDialog);
Vue.component('the-image-viewer', TheImageViewer);
Vue.component('the-pager', ThePager);
Vue.component('v-distpicker', VDistpicker);

Vue.config.productionTip = false;

Vue.use(ElementUI);
Vue.prototype.$echarts = echarts;
Vue.prototype.$global = Global;
Vue.prototype.$util = util;
Vue.prototype.$ajax = Api;
Vue.prototype.$setStore = setStore;
Vue.prototype.$getStore = getStore;
Vue.prototype.$removeStore = removeStore;
Vue.prototype.$authInfo = authInfo;
Vue.prototype.$setWs = wsConnection;
Vue.prototype.$setWsRemote = wsConnectionRomote;

Vue.prototype.$video = Video;
Vue.prototype.$dict = Dict;
Vue.prototype.$validate = Validate;

Vue.use(Viewer, {
  defaultOptions: {
    zIndex: 9999,
  },
});
Vue.use(Vuex);
// 过滤器统一处理加载
Object.keys(filters).forEach((key) => {
  Vue.filter(key, filters[key]);
});

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>',
  mounted() {
    util.initRouter(this); // 初始化菜单
  },
});

// /**
//  * @description
//  * @author (Set the text for this tag by adding docthis.authorName to your settings file.)
//  * @param { number } type 1 localStorage 2 sessionStorage
//  * @param { string } key 键
//  * @param { string } data 要存储的数据
//  * @returns
//  */
//  Vue.prototype.$addStorageEvent = function (type, key, data) {
//     if (type === 1) {
//     // 创建一个StorageEvent事件
//     var newStorageEvent = document.createEvent('StorageEvent');
//     const storage = {
//         setItem: function (k, val) {
//             localStorage.setItem(k, val);
//             // 初始化创建的事件
//             newStorageEvent.initStorageEvent('setItem', false, false, k, null, val, null, null);
//             // 派发对象
//             window.dispatchEvent(newStorageEvent);
//         }
//     }
//     return storage.setItem(key, data);
//   } else {
//     // 创建一个StorageEvent事件
//     var newStorageEvent = document.createEvent('StorageEvent');
//     const storage = {
//         setItem: function (k, val) {
//             sessionStorage.setItem(k, val);
//             // 初始化创建的事件
//             newStorageEvent.initStorageEvent('setItem', false, false, k, null, val, null, null);
//             // 派发对象
//             window.dispatchEvent(newStorageEvent);
//         }
//     }
//     return storage.setItem(key, data);
//   }
// }

Vue.directive('title', {
  inserted(el, binding) {
    // document.title = el.dataset.title
    document.title = getStore('hospitalName') || global.hospitalName;
  },
});
